const {
  JIN_RI_YUN_SHI
} = require('../../../config')

const constellationList = [
  '水瓶座',
  '双鱼座',
  '白羊座',
  '金牛座',
  '双子座',
  '巨蟹座',
  '狮子座',
  '处女座',
  '天秤座',
  '天蝎座',
  '射手座',
  '摩羯座'
]
// 聚合数据，星座运势
export default class Constellation {
  init ({bot, msg, gameExecList}) {
    if (!this.validate(gameExecList)) return
    this.getConstellationInfo(bot, msg, gameExecList[1])
  }

  validate (gameExecList) {
    return gameExecList[2] === JIN_RI_YUN_SHI && constellationList.includes(gameExecList[1])
  }

  getConstellationInfo (bot, msg, consName) {
    bot
      .request({
        method: 'GET',
        url: 'http://web.juhe.cn/constellation/getAll',
        params: {
          key: 'cbe3cca8572b9b1d8d3e263b15fba996',
          consName,
          type: 'today' // 运势类型：today,tomorrow,week,month,year
        }
      })
      .then(res => {
        const resObj = res.data
        const replyStr = `星座名称: ${resObj.name}\n综合指数: ${resObj.all}\n幸运颜色: ${resObj.color}\n健康指数: ${resObj.health}\n爱情指数: ${resObj.love}\n财运指数: ${resObj.money}\n幸运数字: ${resObj.number}\n速配星座: ${resObj.QFriend}\n今日概述: ${resObj.summary}\n工作指数: ${resObj.work}`
        bot.sendMsg(replyStr, msg.FromUserName)
        bot.emit('exitGame', msg.FromUserName)
      })
  }
}
